package com.risesoftware.battlebugs;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

public abstract class BattleShip extends Activity {

	   int           xx    = 7;
	   int           yy    = 7;

	   List<Integer> boats = new ArrayList<Integer>();


	   /** Called when the activity is first created. */
	   @Override
	   public void onCreate(Bundle savedInstanceState) {
	      super.onCreate(savedInstanceState);	      

	      boats.add(2);
	      boats.add(3);
	      boats.add(4);
	   }

	   protected void resetBoard() {
		      RelativeLayout layout = (RelativeLayout) findViewById(R.id.rellyt_gameBoard);

		      Button buttonLast = null;
		      Button buttonX = null;
		      for (int x = 0; x < xx; x++) {
		         Button button = new Button(getApplicationContext());
		         button.setVisibility(View.VISIBLE);
		         button.setText("" + (x * 10));
		         button.setId(1000 + x);

		         if (buttonX == null) {
		            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
		                  RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

		            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		            button.setLayoutParams(layoutParams);
		         }
		         else {
		            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
		                  RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

		            layoutParams.addRule(RelativeLayout.BELOW, buttonX.getId());
		            button.setLayoutParams(layoutParams);
		         }

		         layout.addView(button);

		         buttonX = buttonLast = button;

		         for (int y = 0; y < yy - 1; y++) {
		            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
		                  RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

		            button = new Button(getApplicationContext());
		            button.setId(1500 + (x * 100) + y);
		            button.setVisibility(View.VISIBLE);
		            button.setText("" + (x * 10 + (y + 1)));
		            layoutParams.addRule(RelativeLayout.RIGHT_OF, buttonLast.getId());
		            layoutParams.addRule(RelativeLayout.ALIGN_TOP, buttonLast.getId());
		            button.setLayoutParams(layoutParams);
		            layout.addView(button, layoutParams);

		            buttonLast = button;
		         }
		      }
		   }	
}
